package com.minimalist.lindi.mapper;

import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.po.LindiSubsidyApplicationPayRecord;
import com.minimalist.common.entity.lindi.vo.subsidyapplicationpayrecord.LindiSubsidyApplicationPayRecordQueryVO;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;

import java.util.List;

/**
 * 林地指标交易平台_补贴申请支付记录表 映射层。
 *
 * @author 11987
 * @since 2025-06-09
 */
public interface LindiSubsidyApplicationPayRecordMapper extends BaseMapper<LindiSubsidyApplicationPayRecord>{

    /**
     * 根据ID查询补贴申请支付记录
     *
     * @param subsidyPayRecordId 补贴申请支付记录ID
     * @return 补贴申请支付记录
     */
    default LindiSubsidyApplicationPayRecord selectSubsidyApplicationPayRecordBySubsidyApplicationPayRecordId(Long subsidyPayRecordId){
        return selectOneByQuery(QueryWrapper.create().eq(
                LindiSubsidyApplicationPayRecord::getSubsidyApplicationPayRecordId
                , subsidyPayRecordId));
    }

    /**
     * 根据ID查询补贴申请支付记录
     *
     * @param subsidyApplicationPayRecordId 补贴申请支付记录ID
     * @return 补贴申请支付记录
     */
    default LindiSubsidyApplicationPayRecord getSubsidyApplicationPayRecordById(Long subsidyApplicationPayRecordId){
        return selectOneByQuery(QueryWrapper.create()
                .eq(LindiSubsidyApplicationPayRecord::getSubsidyApplicationPayRecordId
                        , subsidyApplicationPayRecordId));
    }

    /**
     * 分页查询补贴申请支付记录列表
     *
     * @param queryVO 查询条件
     * @return 分页结果
     */
    default Page<LindiSubsidyApplicationPayRecord> selectPageSubsidyApplicationPayRecordList(LindiSubsidyApplicationPayRecordQueryVO queryVO){
        return paginate(queryVO.getPageNum(), queryVO.getPageSize(),
                QueryWrapper.create()
                        .eq(LindiSubsidyApplicationPayRecord::getSubsidyApplicationPayRecordId, queryVO.getSubsidyPayRecordId())
                        .eq(LindiSubsidyApplicationPayRecord::getPayType, queryVO.getPayType())
                        .eq(LindiSubsidyApplicationPayRecord::getPayMethod, queryVO.getPayMethod())
                        .ge(LindiSubsidyApplicationPayRecord::getPayDate, queryVO.getStartDate())
                        .le(LindiSubsidyApplicationPayRecord::getPayDate, queryVO.getEndDate())
                        .orderBy(LindiSubsidyApplicationPayRecord::getCreateTime, false));
    }

    /**
     * 根据支付类型查询支付记录列表
     *
     * @param payType 支付类型
     * @return 支付记录列表
     */
    default List<LindiSubsidyApplicationPayRecord> selectPayRecordListByPayType(String payType){
        return selectListByQuery(QueryWrapper.create()
                .eq(LindiSubsidyApplicationPayRecord::getPayType, payType)
                .orderBy(LindiSubsidyApplicationPayRecord::getCreateTime, false));
    }

    /**
     * 根据支付方式查询支付记录列表
     *
     * @param payMethod 支付方式
     * @return 支付记录列表
     */
    default List<LindiSubsidyApplicationPayRecord> selectPayRecordListByPayMethod(String payMethod){
        return selectListByQuery(QueryWrapper.create()
                .eq(LindiSubsidyApplicationPayRecord::getPayMethod, payMethod)
                .orderBy(LindiSubsidyApplicationPayRecord::getCreateTime, false));
    }


    /**
     * 根据补贴申请ID查询支付记录列表
     *
     * @param subsidyApplicationId 补贴申请ID
     * @return 支付记录列表
     */
    default List<LindiSubsidyApplicationPayRecord> selectPayRecordListBySubsidyApplicationId(Long subsidyApplicationId){
        return selectListByQuery(QueryWrapper.create()
                .eq(LindiSubsidyApplicationPayRecord::getSubsidyApplicationId
                        , subsidyApplicationId)
                .orderBy(LindiSubsidyApplicationPayRecord::getCreateTime, false));
    }

    /**
     * 根据补贴申请ID分页查询支付记录列表
     *
     * @param subsidyApplicationId 补贴申请ID
     * @param pageNum              页码
     * @param pageSize             页大小
     * @return 支付记录分页结果
     */
    default PageResp<LindiSubsidyApplicationPayRecord> getSubsidyApplicationPayRecordPageBySubsidyApplicationId(Long subsidyApplicationId, Integer pageNum, Integer pageSize){
        Page<LindiSubsidyApplicationPayRecord> page = paginate(pageNum, pageSize,
                QueryWrapper.create()
                        .eq(LindiSubsidyApplicationPayRecord::getSubsidyApplicationId
                                , subsidyApplicationId)
                        .orderBy(LindiSubsidyApplicationPayRecord::getPayMoney, true));
        return new PageResp<>(page.getRecords(), page.getTotalRow());
    }

    /**
     * 根据补贴申请支付记录ID删除补贴申请支付记录
     *
     * @param subsidyApplicationPayRecordId 补贴申请支付记录ID
     * @return 删除结果
     */
    default int deleteSubsidyApplicationPayRecordBySubsidyApplicationPayRecordId(
            Long subsidyApplicationPayRecordId){
        return deleteByQuery(QueryWrapper.create()
                .eq(LindiSubsidyApplicationPayRecord::getSubsidyApplicationPayRecordId
                        , subsidyApplicationPayRecordId));
    }
}